<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude, ScopedTypeVariables #-}</span><span>
</span><span id="line-3"></span><span>
</span><span id="line-4"></span><span class="hs-comment">--------------------------------------------------------------------------------</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- Module      :  Foreign.Marshal.Pool</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- Copyright   :  (c) Sven Panne 2002-2004</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-9"></span><span class="hs-comment">--</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Maintainer  :  sven.panne@aedion.de</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Stability   :  provisional</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-13"></span><span class="hs-comment">--</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- This module contains support for pooled memory management. Under this scheme,</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- (re-)allocations belong to a given pool, and everything in a pool is</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- deallocated when the pool itself is deallocated. This is useful when</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- 'Foreign.Marshal.Alloc.alloca' with its implicit allocation and deallocation</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- is not flexible enough, but explicit uses of 'Foreign.Marshal.Alloc.malloc'</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- and 'free' are too awkward.</span><span>
</span><span id="line-20"></span><span class="hs-comment">--</span><span>
</span><span id="line-21"></span><span class="hs-comment">--------------------------------------------------------------------------------</span><span>
</span><span id="line-22"></span><span>
</span><span id="line-23"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Foreign.Marshal.Pool</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-24"></span><span>   </span><span class="annot"><span class="hs-comment">-- * Pool management</span></span><span>
</span><span id="line-25"></span><span>   </span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier">Pool</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-26"></span><span>   </span><span class="annot"><a href="Foreign.Marshal.Pool.html#newPool"><span class="hs-identifier">newPool</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-27"></span><span>   </span><span class="annot"><a href="Foreign.Marshal.Pool.html#freePool"><span class="hs-identifier">freePool</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-28"></span><span>   </span><span class="annot"><a href="Foreign.Marshal.Pool.html#withPool"><span class="hs-identifier">withPool</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-29"></span><span>
</span><span id="line-30"></span><span>   </span><span class="annot"><span class="hs-comment">-- * (Re-)Allocation within a pool</span></span><span>
</span><span id="line-31"></span><span>   </span><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledMalloc"><span class="hs-identifier">pooledMalloc</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-32"></span><span>   </span><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledMallocBytes"><span class="hs-identifier">pooledMallocBytes</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-33"></span><span>
</span><span id="line-34"></span><span>   </span><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledRealloc"><span class="hs-identifier">pooledRealloc</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-35"></span><span>   </span><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledReallocBytes"><span class="hs-identifier">pooledReallocBytes</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-36"></span><span>
</span><span id="line-37"></span><span>   </span><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledMallocArray"><span class="hs-identifier">pooledMallocArray</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-38"></span><span>   </span><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledMallocArray0"><span class="hs-identifier">pooledMallocArray0</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-39"></span><span>
</span><span id="line-40"></span><span>   </span><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledReallocArray"><span class="hs-identifier">pooledReallocArray</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-41"></span><span>   </span><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledReallocArray0"><span class="hs-identifier">pooledReallocArray0</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-42"></span><span>
</span><span id="line-43"></span><span>   </span><span class="annot"><span class="hs-comment">-- * Combined allocation and marshalling</span></span><span>
</span><span id="line-44"></span><span>   </span><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledNew"><span class="hs-identifier">pooledNew</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-45"></span><span>   </span><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledNewArray"><span class="hs-identifier">pooledNewArray</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-46"></span><span>   </span><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledNewArray0"><span class="hs-identifier">pooledNewArray0</span></a></span><span>
</span><span id="line-47"></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-48"></span><span>
</span><span id="line-49"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>              </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier">Int</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Base.html#Monad"><span class="hs-identifier">Monad</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Base.html#."><span class="hs-operator">(.)</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Base.html#liftM"><span class="hs-identifier">liftM</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier">not</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-50"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Err.html"><span class="hs-identifier">GHC.Err</span></a></span><span>               </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Err.html#undefined"><span class="hs-identifier">undefined</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Exception.html"><span class="hs-identifier">GHC.Exception</span></a></span><span>         </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Exception.html#throw"><span class="hs-identifier">throw</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-52"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.html"><span class="hs-identifier">GHC.IO</span></a></span><span>                </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier">IO</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#mask"><span class="hs-identifier">mask</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#catchAny"><span class="hs-identifier">catchAny</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-53"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IORef.html"><span class="hs-identifier">GHC.IORef</span></a></span><span>             </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.IORef.html#IORef"><span class="hs-identifier">IORef</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IORef.html#newIORef"><span class="hs-identifier">newIORef</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IORef.html#readIORef"><span class="hs-identifier">readIORef</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier">writeIORef</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-54"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.List.html"><span class="hs-identifier">GHC.List</span></a></span><span>              </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.List.html#elem"><span class="hs-identifier">elem</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.List.html#length"><span class="hs-identifier">length</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-55"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Num.html"><span class="hs-identifier">GHC.Num</span></a></span><span>               </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Num.html#Num"><span class="hs-identifier">Num</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-56"></span><span>
</span><span id="line-57"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.OldList.html"><span class="hs-identifier">Data.OldList</span></a></span><span>          </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Data.OldList.html#delete"><span class="hs-identifier">delete</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-58"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Marshal.Alloc.html"><span class="hs-identifier">Foreign.Marshal.Alloc</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#mallocBytes"><span class="hs-identifier">mallocBytes</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#reallocBytes"><span class="hs-identifier">reallocBytes</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Foreign.Marshal.Alloc.html#free"><span class="hs-identifier">free</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-59"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Marshal.Array.html"><span class="hs-identifier">Foreign.Marshal.Array</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Foreign.Marshal.Array.html#pokeArray"><span class="hs-identifier">pokeArray</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Foreign.Marshal.Array.html#pokeArray0"><span class="hs-identifier">pokeArray0</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-60"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Marshal.Error.html"><span class="hs-identifier">Foreign.Marshal.Error</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Foreign.Marshal.Error.html#throwIf"><span class="hs-identifier">throwIf</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-61"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Ptr.html"><span class="hs-identifier">Foreign.Ptr</span></a></span><span>           </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier">Ptr</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier">castPtr</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-62"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Storable.html"><span class="hs-identifier">Foreign.Storable</span></a></span><span>      </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier">Storable</span></a></span><span class="hs-special">(</span><span class="annot"><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier">sizeOf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Foreign.Storable.html#poke"><span class="hs-identifier">poke</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-63"></span><span>
</span><span id="line-64"></span><span class="hs-comment">--------------------------------------------------------------------------------</span><span>
</span><span id="line-65"></span><span>
</span><span id="line-66"></span><span class="hs-comment">-- To avoid non-H2010 stuff like existentially quantified data constructors, we</span><span>
</span><span id="line-67"></span><span class="hs-comment">-- simply use pointers to () below. Not very nice, but...</span><span>
</span><span id="line-68"></span><span>
</span><span id="line-69"></span><span class="hs-comment">-- | A memory pool.</span><span>
</span><span id="line-70"></span><span>
</span><span id="line-71"></span><span class="hs-keyword">newtype</span><span> </span><span id="Pool"><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-var">Pool</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="Pool"><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-var">Pool</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IORef.html#IORef"><span class="hs-identifier hs-type">IORef</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-72"></span><span>
</span><span id="line-73"></span><span class="hs-comment">-- | Allocate a fresh memory pool.</span><span>
</span><span id="line-74"></span><span>
</span><span id="line-75"></span><span class="annot"><a href="Foreign.Marshal.Pool.html#newPool"><span class="hs-identifier hs-type">newPool</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span>
</span><span id="line-76"></span><span id="newPool"><span class="annot"><span class="annottext">newPool :: IO Pool
</span><a href="Foreign.Marshal.Pool.html#newPool"><span class="hs-identifier hs-var hs-var">newPool</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(IORef [Ptr ()] -&gt; Pool) -&gt; IO (IORef [Ptr ()]) -&gt; IO Pool
forall (m :: * -&gt; *) a1 r. Monad m =&gt; (a1 -&gt; r) -&gt; m a1 -&gt; m r
</span><a href="GHC.Base.html#liftM"><span class="hs-identifier hs-var">liftM</span></a></span><span> </span><span class="annot"><span class="annottext">IORef [Ptr ()] -&gt; Pool
</span><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-var">Pool</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Ptr ()] -&gt; IO (IORef [Ptr ()])
forall a. a -&gt; IO (IORef a)
</span><a href="GHC.IORef.html#newIORef"><span class="hs-identifier hs-var">newIORef</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-77"></span><span>
</span><span id="line-78"></span><span class="hs-comment">-- | Deallocate a memory pool and everything which has been allocated in the</span><span>
</span><span id="line-79"></span><span class="hs-comment">-- pool itself.</span><span>
</span><span id="line-80"></span><span>
</span><span id="line-81"></span><span class="annot"><a href="Foreign.Marshal.Pool.html#freePool"><span class="hs-identifier hs-type">freePool</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-82"></span><span id="freePool"><span class="annot"><span class="annottext">freePool :: Pool -&gt; IO ()
</span><a href="Foreign.Marshal.Pool.html#freePool"><span class="hs-identifier hs-var hs-var">freePool</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span id="local-6989586621679538183"><span class="annot"><span class="annottext">IORef [Ptr ()]
</span><a href="#local-6989586621679538183"><span class="hs-identifier hs-var">pool</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IORef [Ptr ()] -&gt; IO [Ptr ()]
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef [Ptr ()]
</span><a href="#local-6989586621679538183"><span class="hs-identifier hs-var">pool</span></a></span><span> </span><span class="annot"><span class="annottext">IO [Ptr ()] -&gt; ([Ptr ()] -&gt; IO ()) -&gt; IO ()
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">[Ptr ()] -&gt; IO ()
forall {a}. [Ptr a] -&gt; IO ()
</span><a href="#local-6989586621679538182"><span class="hs-identifier hs-var">freeAll</span></a></span><span>
</span><span id="line-83"></span><span>   </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621679538182"><span class="annot"><span class="annottext">freeAll :: [Ptr a] -&gt; IO ()
</span><a href="#local-6989586621679538182"><span class="hs-identifier hs-var hs-var">freeAll</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-84"></span><span>         </span><span class="annot"><a href="#local-6989586621679538182"><span class="hs-identifier hs-var">freeAll</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679538179"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538179"><span class="hs-identifier hs-var">p</span></a></span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679538178"><span class="annot"><span class="annottext">[Ptr a]
</span><a href="#local-6989586621679538178"><span class="hs-identifier hs-var">ps</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; IO ()
forall a. Ptr a -&gt; IO ()
</span><a href="Foreign.Marshal.Alloc.html#free"><span class="hs-identifier hs-var">free</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538179"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO () -&gt; IO ()
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; m b -&gt; m b
</span><a href="GHC.Base.html#%3E%3E"><span class="hs-operator hs-var">&gt;&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[Ptr a] -&gt; IO ()
</span><a href="#local-6989586621679538182"><span class="hs-identifier hs-var">freeAll</span></a></span><span> </span><span class="annot"><span class="annottext">[Ptr a]
</span><a href="#local-6989586621679538178"><span class="hs-identifier hs-var">ps</span></a></span><span>
</span><span id="line-85"></span><span>
</span><span id="line-86"></span><span class="hs-comment">-- | Execute an action with a fresh memory pool, which gets automatically</span><span>
</span><span id="line-87"></span><span class="hs-comment">-- deallocated (including its contents) after the action has finished.</span><span>
</span><span id="line-88"></span><span>
</span><span id="line-89"></span><span id="local-6989586621679538276"><span class="annot"><a href="Foreign.Marshal.Pool.html#withPool"><span class="hs-identifier hs-type">withPool</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538276"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538276"><span class="hs-identifier hs-type">b</span></a></span></span><span>
</span><span id="line-90"></span><span id="withPool"><span class="annot"><span class="annottext">withPool :: forall b. (Pool -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Pool.html#withPool"><span class="hs-identifier hs-var hs-var">withPool</span></a></span></span><span> </span><span id="local-6989586621679538173"><span class="annot"><span class="annottext">Pool -&gt; IO b
</span><a href="#local-6989586621679538173"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>   </span><span class="hs-comment">-- ATTENTION: cut-n-paste from Control.Exception below!</span><span>
</span><span id="line-91"></span><span>   </span><span class="annot"><span class="annottext">((forall a. IO a -&gt; IO a) -&gt; IO b) -&gt; IO b
forall b. ((forall a. IO a -&gt; IO a) -&gt; IO b) -&gt; IO b
</span><a href="GHC.IO.html#mask"><span class="hs-identifier hs-var">mask</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679538172"><span class="annot"><span class="annottext">forall a. IO a -&gt; IO a
</span><a href="#local-6989586621679538172"><span class="hs-identifier hs-var">restore</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-92"></span><span>      </span><span id="local-6989586621679538171"><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538171"><span class="hs-identifier hs-var">pool</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO Pool
</span><a href="Foreign.Marshal.Pool.html#newPool"><span class="hs-identifier hs-var">newPool</span></a></span><span>
</span><span id="line-93"></span><span>      </span><span id="local-6989586621679538170"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679538170"><span class="hs-identifier hs-var">val</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO b -&gt; (forall e. Exception e =&gt; e -&gt; IO b) -&gt; IO b
forall a. IO a -&gt; (forall e. Exception e =&gt; e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catchAny"><span class="hs-identifier hs-var">catchAny</span></a></span><span>
</span><span id="line-94"></span><span>                </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IO b -&gt; IO b
forall a. IO a -&gt; IO a
</span><a href="#local-6989586621679538172"><span class="hs-identifier hs-var">restore</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Pool -&gt; IO b
</span><a href="#local-6989586621679538173"><span class="hs-identifier hs-var">act</span></a></span><span> </span><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538171"><span class="hs-identifier hs-var">pool</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-95"></span><span>                </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679538166"><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679538166"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">Pool -&gt; IO ()
</span><a href="Foreign.Marshal.Pool.html#freePool"><span class="hs-identifier hs-var">freePool</span></a></span><span> </span><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538171"><span class="hs-identifier hs-var">pool</span></a></span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">e -&gt; IO b
forall a e. Exception e =&gt; e -&gt; a
</span><a href="GHC.Exception.html#throw"><span class="hs-identifier hs-var">throw</span></a></span><span> </span><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679538166"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-96"></span><span>      </span><span class="annot"><span class="annottext">Pool -&gt; IO ()
</span><a href="Foreign.Marshal.Pool.html#freePool"><span class="hs-identifier hs-var">freePool</span></a></span><span> </span><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538171"><span class="hs-identifier hs-var">pool</span></a></span><span>
</span><span id="line-97"></span><span>      </span><span class="annot"><span class="annottext">b -&gt; IO b
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679538170"><span class="hs-identifier hs-var">val</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-98"></span><span>
</span><span id="line-99"></span><span class="hs-comment">--------------------------------------------------------------------------------</span><span>
</span><span id="line-100"></span><span>
</span><span id="line-101"></span><span class="hs-comment">-- | Allocate space for storable type in the given pool. The size of the area</span><span>
</span><span id="line-102"></span><span class="hs-comment">-- allocated is determined by the 'sizeOf' method from the instance of</span><span>
</span><span id="line-103"></span><span class="hs-comment">-- 'Storable' for the appropriate type.</span><span>
</span><span id="line-104"></span><span>
</span><span id="line-105"></span><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledMalloc"><span class="hs-identifier hs-type">pooledMalloc</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679538265"><span class="annot"><a href="#local-6989586621679538265"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538265"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-106"></span><span id="pooledMalloc"><span class="annot"><span class="annottext">pooledMalloc :: forall a. Storable a =&gt; Pool -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledMalloc"><span class="hs-identifier hs-var hs-var">pooledMalloc</span></a></span></span><span> </span><span id="local-6989586621679538161"><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538161"><span class="hs-identifier hs-var">pool</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Pool -&gt; Int -&gt; IO (Ptr a)
forall a. Pool -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledMallocBytes"><span class="hs-identifier hs-var">pooledMallocBytes</span></a></span><span> </span><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538161"><span class="hs-identifier hs-var">pool</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var">sizeOf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
forall a. HasCallStack =&gt; a
</span><a href="GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679538265"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-107"></span><span>
</span><span id="line-108"></span><span class="hs-comment">-- | Allocate the given number of bytes of storage in the pool.</span><span>
</span><span id="line-109"></span><span>
</span><span id="line-110"></span><span id="local-6989586621679538261"><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledMallocBytes"><span class="hs-identifier hs-type">pooledMallocBytes</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538261"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-111"></span><span id="pooledMallocBytes"><span class="annot"><span class="annottext">pooledMallocBytes :: forall a. Pool -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledMallocBytes"><span class="hs-identifier hs-var hs-var">pooledMallocBytes</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span id="local-6989586621679538156"><span class="annot"><span class="annottext">IORef [Ptr ()]
</span><a href="#local-6989586621679538156"><span class="hs-identifier hs-var">pool</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679538155"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679538155"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-112"></span><span>   </span><span id="local-6989586621679538154"><span class="annot"><span class="annottext">Ptr ()
</span><a href="#local-6989586621679538154"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO (Ptr ())
forall a. Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#mallocBytes"><span class="hs-identifier hs-var">mallocBytes</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679538155"><span class="hs-identifier hs-var">size</span></a></span><span>
</span><span id="line-113"></span><span>   </span><span id="local-6989586621679538153"><span class="annot"><span class="annottext">[Ptr ()]
</span><a href="#local-6989586621679538153"><span class="hs-identifier hs-var">ptrs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef [Ptr ()] -&gt; IO [Ptr ()]
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef [Ptr ()]
</span><a href="#local-6989586621679538156"><span class="hs-identifier hs-var">pool</span></a></span><span>
</span><span id="line-114"></span><span>   </span><span class="annot"><span class="annottext">IORef [Ptr ()] -&gt; [Ptr ()] -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef [Ptr ()]
</span><a href="#local-6989586621679538156"><span class="hs-identifier hs-var">pool</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr ()
</span><a href="#local-6989586621679538154"><span class="hs-identifier hs-var">ptr</span></a></span><span class="annot"><span class="annottext">Ptr () -&gt; [Ptr ()] -&gt; [Ptr ()]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">[Ptr ()]
</span><a href="#local-6989586621679538153"><span class="hs-identifier hs-var">ptrs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-115"></span><span>   </span><span class="annot"><span class="annottext">Ptr a -&gt; IO (Ptr a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr () -&gt; Ptr a
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr ()
</span><a href="#local-6989586621679538154"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-116"></span><span>
</span><span id="line-117"></span><span class="hs-comment">-- | Adjust the storage area for an element in the pool to the given size of</span><span>
</span><span id="line-118"></span><span class="hs-comment">-- the required type.</span><span>
</span><span id="line-119"></span><span>
</span><span id="line-120"></span><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledRealloc"><span class="hs-identifier hs-type">pooledRealloc</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679538252"><span class="annot"><a href="#local-6989586621679538252"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538252"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538252"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538252"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-121"></span><span id="pooledRealloc"><span class="annot"><span class="annottext">pooledRealloc :: forall a. Storable a =&gt; Pool -&gt; Ptr a -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledRealloc"><span class="hs-identifier hs-var hs-var">pooledRealloc</span></a></span></span><span> </span><span id="local-6989586621679538148"><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538148"><span class="hs-identifier hs-var">pool</span></a></span></span><span> </span><span id="local-6989586621679538147"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538147"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Pool -&gt; Ptr a -&gt; Int -&gt; IO (Ptr a)
forall a. Pool -&gt; Ptr a -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledReallocBytes"><span class="hs-identifier hs-var">pooledReallocBytes</span></a></span><span> </span><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538148"><span class="hs-identifier hs-var">pool</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538147"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var">sizeOf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
forall a. HasCallStack =&gt; a
</span><a href="GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679538252"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-122"></span><span>
</span><span id="line-123"></span><span class="hs-comment">-- | Adjust the storage area for an element in the pool to the given size.</span><span>
</span><span id="line-124"></span><span>
</span><span id="line-125"></span><span id="local-6989586621679538250"><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledReallocBytes"><span class="hs-identifier hs-type">pooledReallocBytes</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538250"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538250"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-126"></span><span id="pooledReallocBytes"><span class="annot"><span class="annottext">pooledReallocBytes :: forall a. Pool -&gt; Ptr a -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledReallocBytes"><span class="hs-identifier hs-var hs-var">pooledReallocBytes</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span id="local-6989586621679538138"><span class="annot"><span class="annottext">IORef [Ptr ()]
</span><a href="#local-6989586621679538138"><span class="hs-identifier hs-var">pool</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679538137"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538137"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679538136"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679538136"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-127"></span><span>   </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679538135"><span class="annot"><span class="annottext">cPtr :: Ptr b
</span><a href="#local-6989586621679538135"><span class="hs-identifier hs-var hs-var">cPtr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr b
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538137"><span class="hs-identifier hs-var">ptr</span></a></span><span>
</span><span id="line-128"></span><span>   </span><span class="annot"><span class="annottext">[Ptr ()]
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">([Ptr ()] -&gt; Bool)
-&gt; ([Ptr ()] -&gt; String) -&gt; IO [Ptr ()] -&gt; IO [Ptr ()]
forall a. (a -&gt; Bool) -&gt; (a -&gt; String) -&gt; IO a -&gt; IO a
</span><a href="Foreign.Marshal.Error.html#throwIf"><span class="hs-identifier hs-var">throwIf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="annot"><span class="annottext">(Bool -&gt; Bool) -&gt; ([Ptr ()] -&gt; Bool) -&gt; [Ptr ()] -&gt; Bool
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr ()
forall {b}. Ptr b
</span><a href="#local-6989586621679538135"><span class="hs-identifier hs-var">cPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr () -&gt; [Ptr ()] -&gt; Bool
forall a. Eq a =&gt; a -&gt; [a] -&gt; Bool
</span><a href="GHC.List.html#elem"><span class="hs-operator hs-var">`elem`</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="annot"><span class="annottext">[Ptr ()]
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;pointer not in pool&quot;</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IORef [Ptr ()] -&gt; IO [Ptr ()]
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef [Ptr ()]
</span><a href="#local-6989586621679538138"><span class="hs-identifier hs-var">pool</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-129"></span><span>   </span><span id="local-6989586621679538134"><span class="annot"><span class="annottext">Ptr ()
</span><a href="#local-6989586621679538134"><span class="hs-identifier hs-var">newPtr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr () -&gt; Int -&gt; IO (Ptr ())
forall a. Ptr a -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Alloc.html#reallocBytes"><span class="hs-identifier hs-var">reallocBytes</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr ()
forall {b}. Ptr b
</span><a href="#local-6989586621679538135"><span class="hs-identifier hs-var">cPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679538136"><span class="hs-identifier hs-var">size</span></a></span><span>
</span><span id="line-130"></span><span>   </span><span id="local-6989586621679538133"><span class="annot"><span class="annottext">[Ptr ()]
</span><a href="#local-6989586621679538133"><span class="hs-identifier hs-var">ptrs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef [Ptr ()] -&gt; IO [Ptr ()]
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef [Ptr ()]
</span><a href="#local-6989586621679538138"><span class="hs-identifier hs-var">pool</span></a></span><span>
</span><span id="line-131"></span><span>   </span><span class="annot"><span class="annottext">IORef [Ptr ()] -&gt; [Ptr ()] -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef [Ptr ()]
</span><a href="#local-6989586621679538138"><span class="hs-identifier hs-var">pool</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr ()
</span><a href="#local-6989586621679538134"><span class="hs-identifier hs-var">newPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr () -&gt; [Ptr ()] -&gt; [Ptr ()]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr () -&gt; [Ptr ()] -&gt; [Ptr ()]
forall a. Eq a =&gt; a -&gt; [a] -&gt; [a]
</span><a href="Data.OldList.html#delete"><span class="hs-identifier hs-var">delete</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr ()
forall {b}. Ptr b
</span><a href="#local-6989586621679538135"><span class="hs-identifier hs-var">cPtr</span></a></span><span> </span><span class="annot"><span class="annottext">[Ptr ()]
</span><a href="#local-6989586621679538133"><span class="hs-identifier hs-var">ptrs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-132"></span><span>   </span><span class="annot"><span class="annottext">Ptr a -&gt; IO (Ptr a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr () -&gt; Ptr a
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr ()
</span><a href="#local-6989586621679538134"><span class="hs-identifier hs-var">newPtr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-133"></span><span>
</span><span id="line-134"></span><span class="hs-comment">-- | Allocate storage for the given number of elements of a storable type in the</span><span>
</span><span id="line-135"></span><span class="hs-comment">-- pool.</span><span>
</span><span id="line-136"></span><span>
</span><span id="line-137"></span><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledMallocArray"><span class="hs-identifier hs-type">pooledMallocArray</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679538239"><span class="annot"><a href="#local-6989586621679538239"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538239"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538239"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-138"></span><span id="pooledMallocArray"><span class="annot"><span class="annottext">pooledMallocArray :: forall a. Storable a =&gt; Pool -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledMallocArray"><span class="hs-identifier hs-var hs-var">pooledMallocArray</span></a></span></span><span> </span><span id="local-6989586621679538126"><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538126"><span class="hs-identifier hs-var">pool</span></a></span></span><span> </span><span id="local-6989586621679538125"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679538125"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-139"></span><span>    </span><span class="annot"><span class="annottext">Pool -&gt; Int -&gt; IO (Ptr a)
forall a. Pool -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledMallocBytes"><span class="hs-identifier hs-var">pooledMallocBytes</span></a></span><span> </span><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538126"><span class="hs-identifier hs-var">pool</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679538125"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var">sizeOf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
forall a. HasCallStack =&gt; a
</span><a href="GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679538239"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-140"></span><span>
</span><span id="line-141"></span><span class="hs-comment">-- | Allocate storage for the given number of elements of a storable type in the</span><span>
</span><span id="line-142"></span><span class="hs-comment">-- pool, but leave room for an extra element to signal the end of the array.</span><span>
</span><span id="line-143"></span><span>
</span><span id="line-144"></span><span id="local-6989586621679538123"><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledMallocArray0"><span class="hs-identifier hs-type">pooledMallocArray0</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538123"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538123"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-145"></span><span id="pooledMallocArray0"><span class="annot"><span class="annottext">pooledMallocArray0 :: forall a. Storable a =&gt; Pool -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledMallocArray0"><span class="hs-identifier hs-var hs-var">pooledMallocArray0</span></a></span></span><span> </span><span id="local-6989586621679538118"><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538118"><span class="hs-identifier hs-var">pool</span></a></span></span><span> </span><span id="local-6989586621679538117"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679538117"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-146"></span><span>   </span><span class="annot"><span class="annottext">Pool -&gt; Int -&gt; IO (Ptr a)
forall a. Storable a =&gt; Pool -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledMallocArray"><span class="hs-identifier hs-var">pooledMallocArray</span></a></span><span> </span><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538118"><span class="hs-identifier hs-var">pool</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679538117"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-147"></span><span>
</span><span id="line-148"></span><span class="hs-comment">-- | Adjust the size of an array in the given pool.</span><span>
</span><span id="line-149"></span><span>
</span><span id="line-150"></span><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledReallocArray"><span class="hs-identifier hs-type">pooledReallocArray</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679538235"><span class="annot"><a href="#local-6989586621679538235"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538235"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538235"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538235"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-151"></span><span id="pooledReallocArray"><span class="annot"><span class="annottext">pooledReallocArray :: forall a. Storable a =&gt; Pool -&gt; Ptr a -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledReallocArray"><span class="hs-identifier hs-var hs-var">pooledReallocArray</span></a></span></span><span> </span><span id="local-6989586621679538110"><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538110"><span class="hs-identifier hs-var">pool</span></a></span></span><span> </span><span id="local-6989586621679538109"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538109"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679538108"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679538108"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-152"></span><span>    </span><span class="annot"><span class="annottext">Pool -&gt; Ptr a -&gt; Int -&gt; IO (Ptr a)
forall a. Pool -&gt; Ptr a -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledReallocBytes"><span class="hs-identifier hs-var">pooledReallocBytes</span></a></span><span> </span><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538110"><span class="hs-identifier hs-var">pool</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538109"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679538108"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var">sizeOf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
forall a. HasCallStack =&gt; a
</span><a href="GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679538235"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-153"></span><span>
</span><span id="line-154"></span><span class="hs-comment">-- | Adjust the size of an array with an end marker in the given pool.</span><span>
</span><span id="line-155"></span><span>
</span><span id="line-156"></span><span id="local-6989586621679538107"><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledReallocArray0"><span class="hs-identifier hs-type">pooledReallocArray0</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538107"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538107"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538107"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-157"></span><span id="pooledReallocArray0"><span class="annot"><span class="annottext">pooledReallocArray0 :: forall a. Storable a =&gt; Pool -&gt; Ptr a -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledReallocArray0"><span class="hs-identifier hs-var hs-var">pooledReallocArray0</span></a></span></span><span> </span><span id="local-6989586621679538102"><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538102"><span class="hs-identifier hs-var">pool</span></a></span></span><span> </span><span id="local-6989586621679538101"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538101"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679538100"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679538100"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-158"></span><span>   </span><span class="annot"><span class="annottext">Pool -&gt; Ptr a -&gt; Int -&gt; IO (Ptr a)
forall a. Storable a =&gt; Pool -&gt; Ptr a -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledReallocArray"><span class="hs-identifier hs-var">pooledReallocArray</span></a></span><span> </span><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538102"><span class="hs-identifier hs-var">pool</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538101"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679538100"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-159"></span><span>
</span><span id="line-160"></span><span class="hs-comment">--------------------------------------------------------------------------------</span><span>
</span><span id="line-161"></span><span>
</span><span id="line-162"></span><span class="hs-comment">-- | Allocate storage for a value in the given pool and marshal the value into</span><span>
</span><span id="line-163"></span><span class="hs-comment">-- this storage.</span><span>
</span><span id="line-164"></span><span>
</span><span id="line-165"></span><span id="local-6989586621679538232"><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledNew"><span class="hs-identifier hs-type">pooledNew</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538232"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679538232"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538232"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-166"></span><span id="pooledNew"><span class="annot"><span class="annottext">pooledNew :: forall a. Storable a =&gt; Pool -&gt; a -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledNew"><span class="hs-identifier hs-var hs-var">pooledNew</span></a></span></span><span> </span><span id="local-6989586621679538093"><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538093"><span class="hs-identifier hs-var">pool</span></a></span></span><span> </span><span id="local-6989586621679538092"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679538092"><span class="hs-identifier hs-var">val</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-167"></span><span>   </span><span id="local-6989586621679538091"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538091"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Pool -&gt; IO (Ptr a)
forall a. Storable a =&gt; Pool -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledMalloc"><span class="hs-identifier hs-var">pooledMalloc</span></a></span><span> </span><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538093"><span class="hs-identifier hs-var">pool</span></a></span><span>
</span><span id="line-168"></span><span>   </span><span class="annot"><span class="annottext">Ptr a -&gt; a -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; a -&gt; IO ()
</span><a href="Foreign.Storable.html#poke"><span class="hs-identifier hs-var">poke</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538091"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679538092"><span class="hs-identifier hs-var">val</span></a></span><span>
</span><span id="line-169"></span><span>   </span><span class="annot"><span class="annottext">Ptr a -&gt; IO (Ptr a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538091"><span class="hs-identifier hs-var">ptr</span></a></span><span>
</span><span id="line-170"></span><span>
</span><span id="line-171"></span><span class="hs-comment">-- | Allocate consecutive storage for a list of values in the given pool and</span><span>
</span><span id="line-172"></span><span class="hs-comment">-- marshal these values into it.</span><span>
</span><span id="line-173"></span><span>
</span><span id="line-174"></span><span id="local-6989586621679538230"><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledNewArray"><span class="hs-identifier hs-type">pooledNewArray</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538230"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679538230"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538230"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-175"></span><span id="pooledNewArray"><span class="annot"><span class="annottext">pooledNewArray :: forall a. Storable a =&gt; Pool -&gt; [a] -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledNewArray"><span class="hs-identifier hs-var hs-var">pooledNewArray</span></a></span></span><span> </span><span id="local-6989586621679538084"><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538084"><span class="hs-identifier hs-var">pool</span></a></span></span><span> </span><span id="local-6989586621679538083"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679538083"><span class="hs-identifier hs-var">vals</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-176"></span><span>   </span><span id="local-6989586621679538082"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538082"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Pool -&gt; Int -&gt; IO (Ptr a)
forall a. Storable a =&gt; Pool -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledMallocArray"><span class="hs-identifier hs-var">pooledMallocArray</span></a></span><span> </span><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538084"><span class="hs-identifier hs-var">pool</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[a] -&gt; Int
forall a. [a] -&gt; Int
</span><a href="GHC.List.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679538083"><span class="hs-identifier hs-var">vals</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-177"></span><span>   </span><span class="annot"><span class="annottext">Ptr a -&gt; [a] -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; [a] -&gt; IO ()
</span><a href="Foreign.Marshal.Array.html#pokeArray"><span class="hs-identifier hs-var">pokeArray</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538082"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679538083"><span class="hs-identifier hs-var">vals</span></a></span><span>
</span><span id="line-178"></span><span>   </span><span class="annot"><span class="annottext">Ptr a -&gt; IO (Ptr a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538082"><span class="hs-identifier hs-var">ptr</span></a></span><span>
</span><span id="line-179"></span><span>
</span><span id="line-180"></span><span class="hs-comment">-- | Allocate consecutive storage for a list of values in the given pool and</span><span>
</span><span id="line-181"></span><span class="hs-comment">-- marshal these values into it, terminating the end with the given marker.</span><span>
</span><span id="line-182"></span><span>
</span><span id="line-183"></span><span id="local-6989586621679538226"><span class="annot"><a href="Foreign.Marshal.Pool.html#pooledNewArray0"><span class="hs-identifier hs-type">pooledNewArray0</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538226"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="Foreign.Marshal.Pool.html#Pool"><span class="hs-identifier hs-type">Pool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679538226"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679538226"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679538226"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-184"></span><span id="pooledNewArray0"><span class="annot"><span class="annottext">pooledNewArray0 :: forall a. Storable a =&gt; Pool -&gt; a -&gt; [a] -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledNewArray0"><span class="hs-identifier hs-var hs-var">pooledNewArray0</span></a></span></span><span> </span><span id="local-6989586621679538075"><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538075"><span class="hs-identifier hs-var">pool</span></a></span></span><span> </span><span id="local-6989586621679538074"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679538074"><span class="hs-identifier hs-var">marker</span></a></span></span><span> </span><span id="local-6989586621679538073"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679538073"><span class="hs-identifier hs-var">vals</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-185"></span><span>   </span><span id="local-6989586621679538072"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538072"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Pool -&gt; Int -&gt; IO (Ptr a)
forall a. Storable a =&gt; Pool -&gt; Int -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Pool.html#pooledMallocArray0"><span class="hs-identifier hs-var">pooledMallocArray0</span></a></span><span> </span><span class="annot"><span class="annottext">Pool
</span><a href="#local-6989586621679538075"><span class="hs-identifier hs-var">pool</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[a] -&gt; Int
forall a. [a] -&gt; Int
</span><a href="GHC.List.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679538073"><span class="hs-identifier hs-var">vals</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-186"></span><span>   </span><span class="annot"><span class="annottext">a -&gt; Ptr a -&gt; [a] -&gt; IO ()
forall a. Storable a =&gt; a -&gt; Ptr a -&gt; [a] -&gt; IO ()
</span><a href="Foreign.Marshal.Array.html#pokeArray0"><span class="hs-identifier hs-var">pokeArray0</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679538074"><span class="hs-identifier hs-var">marker</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538072"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679538073"><span class="hs-identifier hs-var">vals</span></a></span><span>
</span><span id="line-187"></span><span>   </span><span class="annot"><span class="annottext">Ptr a -&gt; IO (Ptr a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679538072"><span class="hs-identifier hs-var">ptr</span></a></span><span>
</span><span id="line-188"></span></pre></body></html>